import json
import tornado.web
import tornado.websocket


class ChatSocketHandler(tornado.websocket.WebSocketHandler):
    def open(self):
        self.write_message(json.dumps({
            'from': 'sys',
            'message': '欢迎来到 聊天室'
        }))

    def on_close(self):
        self.write_message(json.dumps({
            'from': 'sys',
            'message': 'close'
        }))

    def on_message(self, message):
        self.write_message(json.dumps({
            'from': 'on_message',
            'message': message
        }))



